#!/usr/bin/env python3
from huggingface_hub import snapshot_download
import os

# --- 配置 ---
# Hugging Face上的模型ID
model_id = "deepseek-ai/deepseek-coder-1.3b-base"
# 希望将模型保存在本地的相对路径文件夹
local_dir = "./deepseek-coder-1.3b-base-offline"

# --- 执行下载 ---
if __name__ == "__main__":
    # 创建目标目录（如果不存在）
    os.makedirs(local_dir, exist_ok=True)

    print(f"Starting download for model '{model_id}' to local directory '{local_dir}'...")
    print("This may take a while depending on your network speed.")

    # 使用snapshot_download下载模型的所有文件
    # local_dir_use_symlinks=False确保是实际复制文件，而不是创建符号链接，便于打包
    try:
        snapshot_download(repo_id=model_id, local_dir=local_dir, local_dir_use_symlinks=False)
        print(f"\nSUCCESS: Model downloaded completely to {local_dir}")
    except Exception as e:
        print(f"\nERROR: An error occurred during download: {e}")
